#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char * myfunc(char * a)
{
    char * x;

    x = (char *)malloc(100);
    strncpy(x, a, 32);

    return x;
}

int main()
{
    char * x;

    x = myfunc("0x666");
    printf("%s\n", x);
    free(x);

	return 0;
}

#if 0

/*
 * intel
 */
00000000000011a9 <myfunc>:
    11a9:	f3 0f 1e fa          	endbr64 
    11ad:	55                   	push   %rbp
    11ae:	48 89 e5             	mov    %rsp,%rbp	// rbp=rsp
    11b1:	48 83 ec 20          	sub    $0x20,%rsp	// rsp-=0x20
    11b5:	48 89 7d e8          	mov    %rdi,-0x18(%rbp)	// rb0-0x18=rdi
    11b9:	bf 64 00 00 00       	mov    $0x64,%edi	// edi=0x64
    11be:	e8 ed fe ff ff       	callq  10b0 <malloc@plt> // malloc(edi)
    11c3:	48 89 45 f8          	mov    %rax,-0x8(%rbp)	// rbp-0x8=rax
    11c7:	48 8b 4d e8          	mov    -0x18(%rbp),%rcx	// rcx=rpb-0x18
    11cb:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=rbp-0x8
    11cf:	ba 20 00 00 00       	mov    $0x20,%edx	// edx=0x20
    11d4:	48 89 ce             	mov    %rcx,%rsi	// rsi=rcx
    11d7:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    11da:	e8 b1 fe ff ff       	callq  1090 <strncpy@plt> // strncpy(rdi, rsi, edx)
    11df:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11e3:	c9                   	leaveq 
    11e4:	c3                   	retq   

00000000000011e5 <main>:
    11e5:	f3 0f 1e fa          	endbr64 
    11e9:	55                   	push   %rbp
    11ea:	48 89 e5             	mov    %rsp,%rbp
    11ed:	48 83 ec 10          	sub    $0x10,%rsp	// rsp-=0x10
    11f1:	48 8d 3d 0c 0e 00 00 	lea    0xe0c(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11f8:	e8 ac ff ff ff       	callq  11a9 <myfunc>	// myfunc(rdi)
    11fd:	48 89 45 f8          	mov    %rax,-0x8(%rbp)	// rbp-0x8=rax
    1201:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=rbp-0x8
    1205:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    1208:	e8 93 fe ff ff       	callq  10a0 <puts@plt>	// puts(rdi)
    120d:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=rbp-0x8
    1211:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    1214:	e8 67 fe ff ff       	callq  1080 <free@plt>	// free(rdi)
    1219:	b8 00 00 00 00       	mov    $0x0,%eax
    121e:	c9                   	leaveq 
    121f:	c3                   	retq   

/*
 * arm
 */
000000000040064c <myfunc>:
  40064c:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  400650:	910003fd 	mov	x29, sp
  400654:	f9000fa0 	str	x0, [x29, #24]		// [x29+24]=x0
  400658:	d2800c80 	mov	x0, #0x64                  	// #100
  40065c:	97ffffa1 	bl	4004e0 <malloc@plt>	// malloc(x0)
  400660:	f90017a0 	str	x0, [x29, #40]		// [x29+40]=x0
  400664:	d2800402 	mov	x2, #0x20                  	// #32
  400668:	f9400fa1 	ldr	x1, [x29, #24]		// x1=[x29+24]
  40066c:	f94017a0 	ldr	x0, [x29, #40]		// x0=[x29+40]
  400670:	97ffffb4 	bl	400540 <strncpy@plt>	// strncpy(x0, x1, x2)
  400674:	f94017a0 	ldr	x0, [x29, #40]
  400678:	a8c37bfd 	ldp	x29, x30, [sp], #48
  40067c:	d65f03c0 	ret

0000000000400680 <main>:
  400680:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400684:	910003fd 	mov	x29, sp
  400688:	90000000 	adrp	x0, 400000 <_init-0x4a0>
  40068c:	911da000 	add	x0, x0, #0x768		// x0=400768
  400690:	97ffffef 	bl	40064c <myfunc>		// myfunc(x0)
  400694:	f9000fa0 	str	x0, [x29, #24]		// [x29+24]=x0
  400698:	f9400fa0 	ldr	x0, [x29, #24]		// x0=[x29+24]
  40069c:	97ffffa1 	bl	400520 <puts@plt>	// puts(x0)
  4006a0:	f9400fa0 	ldr	x0, [x29, #24]		// x0=[x29+24]
  4006a4:	97ffffa3 	bl	400530 <free@plt>	// free(x0
  4006a8:	52800000 	mov	w0, #0x0                   	// #0
  4006ac:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4006b0:	d65f03c0 	ret
  4006b4:	00000000 	.inst	0x00000000 ; undefined

#endif
